package com.hyt.it.ogt.kq.common.gov.enums;

import com.hyt.it.ogt.kq.common.gov.constant.ResponseCode;
import com.hyt.it.ogt.kq.common.config.exception.KqException;
import lombok.Getter;

/**
 * 树结构节点类型枚举
 *
 * @author wangg
 */
@Getter
public enum TreeNodeTypeEnum {

    /**
     * 树节点类型
     */
    TREE_NODE_TYPE_DEPT("dept", "部门"),
    TREE_NODE_TYPE_USER("user", "人员"),

    ;

    private final String code;
    private final String name;

    TreeNodeTypeEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取类型枚举
     *
     * @param code 类型code
     * @return 类型枚举
     * @throws KqException 异常
     */
    public static TreeNodeTypeEnum getByCode(String code) throws KqException {
        for (TreeNodeTypeEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        //用户类型不存在
        throw new KqException(ResponseCode.ERROR_TREE_NODE_TYPE_NOT_FOUND.getCode(),
                "树节点类型不存在");
    }

}
